/**
 * Copyright (c) 2010-2011 julewa.com.  
 * All rights reserved. 
 * 
 * @author Huang Benhua
 * @date 2011-2-20
 * 
**/
package com.julewa.db.ibatis.loading;

import com.julewa.db.BeanInfo.ColumnInfo;
import com.julewa.db.info.PropertyInfo;

public class IbatisColumnInfo{
	
	private PropertyInfo info = null;
	
	private String dbname = null; 
	private String dbtype = null;
	private String sqlname = null;
	
	//
	public IbatisColumnInfo(IbatisConfiguration conf, String dbcode, PropertyInfo info){
		this.info = info;
		this.dbname = conf.getColPrefix() + info.getCode().toUpperCase();
		this.dbtype = conf.getDbTypeOf(info.getDataType());
		this.info.setLabel(conf.findLabel(dbcode, info.getLabel()));
	}
	
	public ColumnInfo getInfo(){
		return info;
	}
	
	public String getCode(){
		return info.getCode();
	}

	public String getDbname() {
		return dbname;
	}

	public String getDbtype() {
		return dbtype;
	}

	public String getValName(){
		if(sqlname == null){
			sqlname = "#" + info.getCode() + ":" + dbtype + "#";
		}
		return sqlname;
	}
	
	public String getTypeName(){
		return info.getDataType().getLabel();
	}
	
	public boolean isNumberType(){
		switch(info.getDataType()){
		case INT:case LONG:
			return true;
		default:
			return false;
		}
	}
	
	public String toString(){
		return info.toString(); 
	}
	
}
